﻿using System;

namespace Sidvall.WorkItemManager.Web.Host
{
	public class Global : System.Web.HttpApplication
	{
		#region Application

		protected void Application_Start(object sender, EventArgs e)
		{
		}
		protected void Application_BeginRequest(object sender, EventArgs e)
		{
			switch (Request.Url.Scheme)
			{
				case "http":
					var path = "https://" + Request.Url.Host + Request.Url.PathAndQuery;
					Response.Status = "301 Moved Permanently";
					Response.AddHeader("Location", path);
					break;
			}
		}
		protected void Application_AuthenticateRequest(object sender, EventArgs e)
		{
		}
		protected void Application_AcquireRequestState(object sender, EventArgs e)
		{
			if (Sidvall.SystemContext.Current.PrincipalContextManager.GetSessionValue("LoggingOff", false))
			{
				Sidvall.SystemContext.Current.PrincipalContextManager.RemoveSessionValue("LoggingOff");
				Sidvall.SystemContext.Current.PrincipalManager.CurrentPrincipal = null;
			}
		}
		protected void Application_End(object sender, EventArgs e)
		{
		}
		protected void Application_Error(object sender, EventArgs e)
		{
		}

		#endregion
		#region Session

		protected void Session_Start(object sender, EventArgs e)
		{
		}
		protected void Session_End(object sender, EventArgs e)
		{
		}

		#endregion
	}
}